package com.ruoyi.project.distribute.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.distribute.domain.HosDocumentLog;
import com.ruoyi.project.distribute.service.IHosDocumentLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author anran
 */
@RestController
@RequestMapping("/distribute/storage")
public class HosDocumentLogController extends BaseController
{
    @Autowired
    private IHosDocumentLogService hosDocumentLogService;

    /**
     * 创建单据报单信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:storage:add')")
    @Log(title = "单据报单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addLog(@RequestBody Long provideId)
    {
        HosDocumentLog hosDocumentLog = new HosDocumentLog();
        hosDocumentLog.setProvideId(provideId);
        hosDocumentLog.setCreateBy(SecurityUtils.getUsername());
        return toAjax(hosDocumentLogService.insertHosDocumentLog(hosDocumentLog));
    }

    /**
     * 查询单据全部信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:storage:list')")
    @GetMapping("/list")
    public TableDataInfo  list(HosDocumentLog hosDocumentLog)
    {
        startPage();
        List<HosDocumentLog> list = hosDocumentLogService.selectHosDocumentList(hosDocumentLog);
        return getDataTable(list);
    }

    /**
     * 根据单据ID和供应商ID查询 对应信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:storage:list')")
    @GetMapping("/get")
    public TableDataInfo  query(String documentlogId, Long provide )
    {
        startPage();
        List<HosDocumentLog> list = hosDocumentLogService
                .selectHosDocumentLogByDocumentLogIdAndProvideId(documentlogId, provide);
        return getDataTable(list);
    }

    /**
     * 根据供应商ID 和 申请人 查询单据报单表
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:list')")
    @GetMapping("/getList")
    public TableDataInfo  getList(Long provideId, String documentlogApply)
    {
        startPage();
        List<HosDocumentLog> list = hosDocumentLogService.selectHosDocumentLogInAudit(provideId, documentlogApply);
        return getDataTable(list);
    }

    /**
     * 修改单据报单表 审核状态
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @PutMapping("/{documentlogId}")
    public AjaxResult remove(@PathVariable String[] documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogAudit(documentlogId));
    }

    /**
     * 修改单据报单表 审核状态
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @PutMapping("/error/{documentlogId}")
    public AjaxResult updateError(@PathVariable String[] documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogAuditError(documentlogId));
    }

    /**
     * 修改单据报单表 审核状态  已审核
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @GetMapping("/Audit/{documentlogId}")
    public AjaxResult updateAudited(@PathVariable String documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogAudited(documentlogId));
    }

    /**
     * 修改单据报单表 审核状态  作废
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @GetMapping("/invalid/{documentlogId}")
    public AjaxResult updateInvalid(@PathVariable String documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogInvalid(documentlogId));
    }

    /**
     * 修改单据报单表 审核状态  入库成功
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @GetMapping("/success/{documentlogId}")
    public AjaxResult updateSuccess(@PathVariable String documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogSuccess(documentlogId));
    }

    /**
     * 修改单据报单表 审核状态  入库成功
     */
    @PreAuthorize("@ss.hasPermi('distribute:audit:edit')")
    @Log(title = "单据报单信息", businessType = BusinessType.UPDATE)
    @GetMapping("/toAudit/{documentlogId}")
    public AjaxResult toAudit(@PathVariable String documentlogId)
    {
        return toAjax(hosDocumentLogService.updateHosDocumentLogSuccess(documentlogId));
    }
}
